package com.xuelang;

import com.alibaba.fastjson2.JSON;
import com.xuelang.pipeline.client.common.result.ApiResult;
import com.xuelang.pipeline.client.pipeline.dto.PipelineConfigDTO;
import com.xuelang.pipeline.entry.pipeline.PipelineController;
import com.xuelang.pipeline.entry.task.TaskDefController;
import com.xuelang.pipeline.infrastructure.task.mapper.TaskDefMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.PropertySource;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.ArrayList;
import java.util.List;

import static com.xuelang.hiforce.base.utils.jwt.RedisUtils.redisTemplate;

/**
 * @author xiwen.zxg
 * @since 2024/5/23
 */
//@SpringBootTest(classes = {SpringbootApp.class})
//@RunWith(SpringRunner.class)
//@PropertySource({"spring.config.location=classpath:application.yml"})
public class Test {

    //public static void main(String[] args) {

        /*
        System.out.println(IdUtil.randomUUID());
        System.out.println(IdUtil.fastUUID());
        System.out.println(IdUtil.fastSimpleUUID());
        System.out.println(IdUtil.simpleUUID());
        System.out.println(IdUtil.getSnowflake().toString());
        System.out.println(IdUtil.getSnowflakeNextId());
        System.out.println(IdUtil.nanoId());
        System.out.println(IdUtil.objectId());
        System.out.println(IdUtil.getSnowflakeNextIdStr());
        System.out.println();
        System.out.println(StringUtils.isNotBlank("   "));
        System.out.println(StringUtils.isNotBlank("123"));
        System.out.println(StringUtils.isNotBlank("null"));
        generateTaskList();
         */
   // }

    public void insertTaskListToDB() {
        /*taskDefMapper.selectList(Wrappers.emptyWrapper());
        List<TaskType> taskTypeList = new ArrayList<>();
        ApiResult<List<TaskType>> result = ApiResult.success(taskTypeList);*/

//        taskTypeList.forEach(taskType -> {
//            String typeCode = taskType.getTypeCode();
//            String typeName = taskType.getTypeName();
//            List<TaskInfo> taskInfoList = taskType.getTaskInfoList();
//            taskInfoList.forEach(taskInfo -> {
//                TaskDefDO taskDefDO = TaskDefDO.builder()
//                        .uuid(IdUtil.fastSimpleUUID())
//                        .name(taskInfo.getTaskName())
//                        .refTag(taskInfo.getTaskCode())
//                        .schemaConfig(JSON.toJSONString(taskInfo.getTaskFieldList()))
//                        .taskDefType(typeCode)
//                        .creatorId("13122222222")
//                        .updaterId("13122222222")
//                        .build();
//                taskDefMapper.insert(taskDefDO);
//            });
//        });
//        /*List<TaskType> taskTypeList = new ArrayList<>();
//        generateTaskList(taskTypeList);
//        ApiResult<List<TaskType>> result2 = ApiResult.success(taskTypeList);
//
//        ApiResult<List<TaskTypeFormDTO>> result = taskDefController.conditionalTaskDefAssemblyList(new TaskDefQuery());
//        System.out.println(JSON.toJSONString(result, SerializerFeature.PrettyFormat, SerializerFeature.SortField));
//        System.out.println();
//        System.out.println();
//        System.out.println(JSON.toJSONString(result2, SerializerFeature.PrettyFormat, SerializerFeature.SortField));*/
//        ApiResult<PipelineConfigDTO> pipelineConfigDTOApiResult = pipelineController.queryPipelineConfig("80e82e2a2d394d65a701ebb4d5e7689c");
//        System.out.println(JSON.toJSONString(pipelineConfigDTOApiResult, SerializerFeature.PrettyFormat, SerializerFeature.SortField));
//
//    }
//
//    private static void generateTaskList(List<TaskType> taskTypeList) {
//        List<TaskInfo> pullCodeList = new ArrayList<>();
//        List<TaskInfo> buildCodeList = new ArrayList<>();
//        List<TaskInfo> buildImageList = new ArrayList<>();
//        List<TaskInfo> scanCodeList = new ArrayList<>();
//        List<TaskInfo> deployCodeList = new ArrayList<>();
//
//        taskTypeList.addBatch(TaskType.builder().typeCode("pull_code").typeName("拉取代码").taskInfoList(pullCodeList).build());
//        taskTypeList.addBatch(TaskType.builder().typeCode("build_code").typeName("代码构建").taskInfoList(buildCodeList).build());
//        taskTypeList.addBatch(TaskType.builder().typeCode("build_image").typeName("镜像构建").taskInfoList(buildImageList).build());
//        taskTypeList.addBatch(TaskType.builder().typeCode("scan_code").typeName("代码扫描").taskInfoList(scanCodeList).build());
//        taskTypeList.addBatch(TaskType.builder().typeCode("deploy_code").typeName("部署").taskInfoList(deployCodeList).build());
//
//        List<TaskField> codeSourceList = new ArrayList<>();
//        codeSourceList.addBatch(TaskField.builder().field("codeRepository").label("代码仓库").editable(false).build());
//        codeSourceList.addBatch(TaskField.builder().field("token").label("token").editable(false).build());
//        codeSourceList.addBatch(TaskField.builder().field("branch").label("分支").component("Select").build());
//        pullCodeList.addBatch(TaskInfo.builder().taskCode("code_source").taskName("代码源").taskFieldList(codeSourceList).build());
//
//        List<TaskField> javaBuildList = new ArrayList<>();
//        javaBuildList.addBatch(TaskField.builder().field("buildCommand").label("构建命令").component("CodeInputComponent").defaultValue("mvn").build());
//        List<TaskField> nodejsBuildList = new ArrayList<>();
//        nodejsBuildList.addBatch(TaskField.builder().field("buildCommand").label("构建命令").component("CodeInputComponent").defaultValue("npm").build());
//        buildCodeList.addBatch(TaskInfo.builder().taskCode("java_build").taskName("JAVA构建").taskFieldList(javaBuildList).build());
//        buildCodeList.addBatch(TaskInfo.builder().taskCode("nodejs_build").taskName("NODEJS构建").taskFieldList(nodejsBuildList).build());
//
//        List<TaskField> customImageList = new ArrayList<>();
//        customImageList.addBatch(TaskField.builder().field("dockerFilePath").label("dockerfile文件路径").required(false).defaultValue("dockerFile").build());
//        customImageList.addBatch(TaskField.builder().field("imageUrl").label("镜像仓库地址").description("默认使用 ***仓库，\n输入格式如registry.com/repository").build());
//        customImageList.addBatch(TaskField.builder().field("imageTag").label("镜像标签").required(false).description("不填默认规则\n生成： 分支+时间戳").build());
//        List<TaskField> goImageList = new ArrayList<>();
//        goImageList.addBatch(TaskField.builder().field("buildCommand").label("构建命令").component("CodeInputComponent").defaultValue("go build").build());
//        goImageList.addBatch(TaskField.builder().field("dockerFilePath").label("dockerfile文件路径").defaultValue("dockerFile").build());
//        goImageList.addBatch(TaskField.builder().field("imageUrl").label("镜像仓库地址").description("输入格式如registry.com/repository").build());
//        goImageList.addBatch(TaskField.builder().field("imageTag").label("镜像标签").required(false).description("不填默认规则\n生成： 分支+时间戳").build());
//        List<TaskField> javaImageList = new ArrayList<>();
//        javaImageList.addBatch(TaskField.builder().field("buildCommand").label("构建命令").component("CodeInputComponent").defaultValue("mvn").build());
//        javaImageList.addBatch(TaskField.builder().field("dockerFilePath").label("dockerfile文件路径").defaultValue("dockerFile").build());
//        javaImageList.addBatch(TaskField.builder().field("imageUrl").label("镜像仓库地址").description("输入格式如registry.com/repository").build());
//        javaImageList.addBatch(TaskField.builder().field("imageTag").label("镜像标签").required(false).description("不填默认规则\n生成： 分支+时间戳").build());
//        List<TaskField> pythonImageList = new ArrayList<>();
//        pythonImageList.addBatch(TaskField.builder().field("dockerFilePath").label("dockerfile文件路径").defaultValue("dockerFile").build());
//        pythonImageList.addBatch(TaskField.builder().field("imageUrl").label("镜像仓库地址").description("输入格式如registry.com/repository").build());
//        pythonImageList.addBatch(TaskField.builder().field("imageTag").label("镜像标签").required(false).description("不填默认规则\n生成： 分支+时间戳").build());
//        List<TaskField> nodejsImageList = new ArrayList<>();
//        nodejsImageList.addBatch(TaskField.builder().field("buildCommand").label("构建命令").component("CodeInputComponent").defaultValue("npm").build());
//        nodejsImageList.addBatch(TaskField.builder().field("dockerFilePath").label("dockerfile文件路径").defaultValue("dockerFile").build());
//        nodejsImageList.addBatch(TaskField.builder().field("imageUrl").label("镜像仓库地址").description("输入格式如registry.com/repository").build());
//        nodejsImageList.addBatch(TaskField.builder().field("imageTag").label("镜像标签").required(false).description("不填默认规则\n生成： 分支+时间戳").build());
//
//        buildImageList.addBatch(TaskInfo.builder().taskCode("custom_image").taskName("自定义镜像构建").taskFieldList(customImageList).build());
//        buildImageList.addBatch(TaskInfo.builder().taskCode("go_image").taskName("GO镜像构建").taskFieldList(goImageList).build());
//        buildImageList.addBatch(TaskInfo.builder().taskCode("java_image").taskName("JAVA镜像构建").taskFieldList(javaImageList).build());
//        buildImageList.addBatch(TaskInfo.builder().taskCode("python_image").taskName("PYTHON镜像构建").taskFieldList(pythonImageList).build());
//        buildImageList.addBatch(TaskInfo.builder().taskCode("nodejs_image").taskName("NODEJS镜像构建").taskFieldList(nodejsImageList).build());
//
//        List<TaskField> javaScanList = new ArrayList<>();
//        javaScanList.addBatch(TaskField.builder().field("codeScan").label("扫描路径").defaultValue("./").build());
//        javaScanList.addBatch(TaskField.builder().field("alertInfo").label("红线信息").component("AlertInfoComponent").required(false).build());
//        List<TaskField> goScanList = new ArrayList<>();
//        goScanList.addBatch(TaskField.builder().field("codeScan").label("扫描路径").defaultValue("./").build());
//        goScanList.addBatch(TaskField.builder().field("alertInfo").label("红线信息").component("AlertInfoComponent").required(false).build());
//        List<TaskField> pythonScanList = new ArrayList<>();
//        pythonScanList.addBatch(TaskField.builder().field("codeScan").label("扫描路径").defaultValue("./").build());
//        pythonScanList.addBatch(TaskField.builder().field("alertInfo").label("红线信息").component("AlertInfoComponent").required(false).build());
//        List<TaskField> nodejsScanList = new ArrayList<>();
//        nodejsScanList.addBatch(TaskField.builder().field("codeScan").label("扫描路径").defaultValue("./").build());
//        nodejsScanList.addBatch(TaskField.builder().field("alertInfo").label("红线信息").component("AlertInfoComponent").required(false).build());
//        List<TaskField> personScanList = new ArrayList<>();
//        personScanList.addBatch(TaskField.builder().field("verifierMode").label("验证者方式").component("Select").editable(false).defaultValue("{\"orSign\":\"或签\"}").build());
//        personScanList.addBatch(TaskField.builder().field("verifierType").label("验证者类型").component("Select").build());
//        personScanList.addBatch(TaskField.builder().field("verifier").label("验证人").component("Select").build());
//        personScanList.addBatch(TaskField.builder().field("verifierRole").label("验证角色").component("Select").build());
//
//        scanCodeList.addBatch(TaskInfo.builder().taskCode("java_scan").taskName("JAVA代码扫描").taskFieldList(javaScanList).build());
//        scanCodeList.addBatch(TaskInfo.builder().taskCode("go_scan").taskName("GO代码扫描").taskFieldList(goScanList).build());
//        scanCodeList.addBatch(TaskInfo.builder().taskCode("python_scan").taskName("PYTHON代码扫描").taskFieldList(pythonScanList).build());
//        scanCodeList.addBatch(TaskInfo.builder().taskCode("nodejs_scan").taskName("NODEJS代码扫描").taskFieldList(nodejsScanList).build());
//        scanCodeList.addBatch(TaskInfo.builder().taskCode("person_scan").taskName("人工卡点").taskFieldList(personScanList).build());
//
//        List<TaskField> scrollDeployList = new ArrayList<>();
//        scrollDeployList.addBatch(TaskField.builder().field("replicas").label("副本数").defaultValue("1").build());
//        scrollDeployList.addBatch(TaskField.builder().field("cpu").label("CPU").defaultValue("0.5").build());
//        scrollDeployList.addBatch(TaskField.builder().field("memory").label("内存").defaultValue("0.5").build());
//        scrollDeployList.addBatch(TaskField.builder().field("port").label("端口").defaultValue("80").build());
//        scrollDeployList.addBatch(TaskField.builder().field("domain").label("域名").description("*.nw.com").build());
//        scrollDeployList.addBatch(TaskField.builder().field("advancedConfig").label("高级配置").component("AdvancedConfigComponent").required(false).build());
//        scrollDeployList.addBatch(TaskField.builder().field("deployStrategy").label("部署策略").editable(false).defaultValue("滚动").build());
//        scrollDeployList.addBatch(TaskField.builder().field("deployEnv").label("部署环境").editable(false).build());
//        List<TaskField> grayDeployList = new ArrayList<>();
//        grayDeployList.addBatch(TaskField.builder().field("replicas").label("副本数").defaultValue("1").build());
//        grayDeployList.addBatch(TaskField.builder().field("cpu").label("CPU").defaultValue("0.5").build());
//        grayDeployList.addBatch(TaskField.builder().field("memory").label("内存").defaultValue("0.5").build());
//        grayDeployList.addBatch(TaskField.builder().field("port").label("端口").defaultValue("80").build());
//        grayDeployList.addBatch(TaskField.builder().field("domain").label("域名").description("*.nw.com").build());
//        grayDeployList.addBatch(TaskField.builder().field("advancedConfig").label("高级配置").component("AdvancedConfigComponent").required(false).build());
//        grayDeployList.addBatch(TaskField.builder().field("deployStrategy").label("部署策略").editable(false).defaultValue("灰度分批").build());
//        grayDeployList.addBatch(TaskField.builder().field("batchesNum").label("分批次数").defaultValue("1").build());
//        grayDeployList.addBatch(TaskField.builder().field("deployEnv").label("部署环境").editable(false).build());
//
//        deployCodeList.addBatch(TaskInfo.builder().taskCode("scroll_deploy").taskName("滚动发布").taskFieldList(scrollDeployList).build());
//        deployCodeList.addBatch(TaskInfo.builder().taskCode("gray_deploy").taskName("灰度发布").taskFieldList(grayDeployList).build());

    }

}
